package com.shelpe.services.sinbad.controller.actionLog.impl.campaign;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;

import com.shelpe.services.sinbad.controller.actionLog.ActionLogDto;
import com.shelpe.services.sinbad.controller.actionLog.ActionLogService;
import com.shelpe.services.sinbad.entity.jpa.AreaList;
import com.shelpe.services.sinbad.entity.jpa.Campaign;
import com.shelpe.services.sinbad.entity.jpa.CampaignLog;

@Service
public class CampaignUpdaeStatusConverter extends ActionLogService {
	@Autowired
	private MessageSource messageSource;

	@Override
	public ActionLogDto convertCampaign(CampaignLog entity, Map<Long, Campaign> campaignMap,List<AreaList> areas) {
		boolean campaignUpdaeStatusConverter = entity.getAction() == CampaignLog.Action.UPDATE_ONLINE_OPEN
				|| entity.getAction() == CampaignLog.Action.UPDATE_ONLINE_PAUSE;
		if (campaignUpdaeStatusConverter) {
			ActionLogDto dto = new ActionLogDto();
			dto.from(entity);
			Campaign campaign = campaignMap.get(entity.getCampaignID());
			if (campaign != null) {
				String status = "暂停";
				String statusMessage = "暂停推广";
				if (entity.getAction() == CampaignLog.Action.UPDATE_ONLINE_OPEN) {
					status = "开启";
					statusMessage = "推广中";
				}
				String[] params = { campaign.getTitle(), status, statusMessage };
				dto.setReason(messageSource.getMessage("message.campaign.status.reason", params, Locale.ENGLISH));
				return dto;
			}
		}
		return null;
	}
}
